package com.atguigui.leetcode;

/**
 * 1252.奇数值单元格的数目
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/7/12 15:10
 */
public class P1252CellsWithOddValuesInAMatrix {

    public static void main(String[] args) {
        Solution solution = new P1252CellsWithOddValuesInAMatrix().new Solution();
        // TO TEST
    }

    class Solution {
        public int oddCells(int m, int n, int[][] indices) {
            int[] rows = new int[m];
            int[] cols = new int[n];

            for (int[] index : indices) {
                rows[index[0]]++;
                cols[index[1]]++;
            }
            int res = 0;
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    //遍历每行每列，判断相加是否为奇数
                    if (((rows[i] + cols[j]) & 1) != 0) {
                        res++;
                    }
                }
            }

            return res;

        }
    }
}
